﻿/*
 * @Autor: PK
 * @Date: 2022/06/14 11:24:SS
 * @Description: 高速公路仿真的调用示例，查看ShkSimulationTest.HighwayTest
 * 
 */

using System;
using System.Collections.Generic;
using ShkSimulation.core.dao;
using ShkSimulation.core.dao.input.loader;
using ShkSimulation.core.dao.output;
using ShkSimulation.core.dao.output.result;
using ShkSimulation.core.dao.statistic;
using ShkSimulation.core.dao.statistic.feature;
using ShkSimulation.core.template;
using ShkSimulation.core.template.model;

namespace ShkSimulation.highway {

	public class HighwayRunner {

		private static Dictionary<string, List<DataReporter>> CreateDataReporters(Network network) {
			Dictionary<string, List<DataReporter>> result = new Dictionary<string, List<DataReporter>>();
			List<DataReporter> reporters = new List<DataReporter>(network.NetworkInput.AllAgencies.Values);
			result.Add("路段", reporters);
			return result;
		}
		
		public static void HighwayRun(NetworkInputData inputData) {
			Network network = HighwayNetwork.BuildNetwork(inputData);
			// 设置数据采集单元
			network.ResultCollector.DataReporterGenerator = new DataReporterGenerator(CreateDataReporters);
			StatisticOptionProvider.RemoveNumberStatisticFunction(StatisticOptionProvider.DefaultAvgValue);
			// 初始化
			NetworkRunInfo runInfo = network.Init(DateTime.Now);
			if (!runInfo.Success) {
				Console.WriteLine(runInfo.RunException.StackTrace);
			}
			int totalDays = 100;
			network.RunWithTerminate(TimeSpan.FromDays(totalDays), TimeSpan.FromHours(100));
			Result result = network.GetCurrentResult();
			ResultData data = result.TakeOutputData();
			ResultShower resultShower = new ConsoleResultShower();
			resultShower.Show(result);
		}


	}

}